var app = new Vue({
    el: "#app",
    data: {
        books: [
            {
                id: 1,
                name: "算法导论",
                date: "2006-9",
                price: 85,
                sum: 1
            },
            {
                id: 2,
                name: "UNIX编程艺术",
                date: "2006-2",
                price: 59,
                sum: 1
            },
            {
                id: 3,
                name: "编程珠玑",
                date: "2008-10",
                price: 39,
                sum: 1
            },
            {
                id: 4,
                name: "代码大全",
                date: "2006-3",
                price: 128,
                sum: 1
            }  
        ]
    },
    methods: {
        inclement: function(index){
            this.books[index].sum++;
            console.log("inclement "  + index);
        },
        declement: function(index){
            this.books[index].sum--;
            console.log("declement " + index);
        },
        removeRow: function(index){
            this.books.splice(index, 1);
        },
        getTotalPrice: function(){
            let totalPrice = 0;
            for (let index = 0; index < this.books.length; index++) {
                totalPrice += this.books[index].price * this.books[index].sum;
            };
            return totalPrice;
        }
    },
    filters: {
        showPrice(price){
            return "￥" + price.toFixed(2)
        }
    }
})